package alone.redis.queue.redisqueue.service;

import alone.redis.queue.redisqueue.util.RedisUtil;

/**
 * 非阻塞方式消费者
 */
public class MessageConsumerService extends Thread {

    private static final String keyName = "redis:queue";

    private String getMessage(){
        return RedisUtil.getJedis().rpop(keyName);
    }

    @Override
    public void run() {
        while (true){
            System.err.println(Thread.currentThread().getName() + "  " + getMessage());
        }
    }

    public static void main(String[] args) {
        MessageConsumerService messageConsumerService = new MessageConsumerService();
        Thread thread1 = new Thread(messageConsumerService,"thread1");
        Thread thread2 = new Thread(messageConsumerService,"thread2");
        thread1.start();
        thread2.start();
    }
}
